<?php
/*
	插件概览
*/
global $_RQ,$_AR;
$merchid=$this->checklogin();
$_RQ['op']=$_RQ['op']?$_RQ['op']:'edit';
$setting = $this->plugin_setting('setting');
$return['types']=array(
	'1'=>'普通订阅号',
	'2'=>'认证订阅号',
	'3'=>'普通服务号',
	'4'=>'认证服务号'
);
if($_RQ['op']=='edit'){
	$this->model('model')->checkworker(2);
	$item=pdo_get('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid));
    $return['plugin_icon']=$item['logo'];
	$item['lat_lng']=$item['lat_lng']?json_decode($item['lat_lng'],true):array();
	$item['codeimg']=$item['codeimg']?json_decode($item['codeimg'],true):array();
	$item['pcd']=$item['pcd']?json_decode($item['pcd'],true):array('province'=>'');
	if(!$item['pcd']['province']){
		$item['pcd']=array('province'=>'');
	}
	$item['onlinetime']=json_decode($item['onlinetime'],true);
	if(strpos($item['diyformdata'],'title') !== false){
		$item['diyfields']=json_decode($item['diyformdata'],true);
	}else{
		$item['diyfields']=$setting['diyformfields'];
	}
	$item['items']=$item['items']?json_decode($item['items'],true):array();
	$item['setting']=$item['setting']?json_decode($item['setting'],true):array();
	//$item['setting']['paifeenew']=$item['setting']['paifee'];
	$item['bankimg']=$item['setting']['bankimg'];
	$item['sets']=$item['sets']?json_decode($item['sets'],true):array('red'=>0);
	//$item['datamids']=json_decode($item['datamids'],true);
	$item['myshop_tpl']=$item['myshop_tpl']?:0;
	$item['onecredit']=$item['onecredit']?json_decode($item['onecredit'],true):array('credit3'=>1);
	if($item['onewechat']){
		$item['onewechat']=json_decode($item['onewechat'],true);
		if(!$item['onewechat']['token']){
			$item['onewechat']=array('isopen'=>0);
		}
	}else{
		$item['onewechat']=array('isopen'=>0);
	}
	$item['url']=SITEROOT.'addons/jy_merch/wxapi.php?merchid='.$item['id'];
	$item['onewechat']['token']=$item['onewechat']['token']?:random(30);
	$item['onewechat']['aeskey']=$item['onewechat']['aeskey']?:random(43);
	$item['app']=$item['app']?json_decode($item['app'],true):array('isopen'=>0);
	$item['appurl']=custom_url('jy_merch/getapp//merchid='.$item['id'],true);
	$item['app']['installbak']=tomedia($item['app']['installbak']);
	$item['cert_file']=$item['onewechat']['cert_file'];
	$item['key_file']=$item['onewechat']['key_file'];
	$item['minsub_pay']=$item['onewechat']['minsub_pay'];
	$account_host=get_account_url();
	$account_tp=str_replace('http://','',$account_host).'custom/';
	$account_apitp=str_replace('http://','',$account_host).'app/';
	$account_url=str_replace('http://','',$account_host).'custom/payresult/wechat_notify.php';
	$return['status']=array('1'=>'开启','0'=>'关闭');
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'商城设置',
		'edit_tab'=>true,
		'edits'=>array(
				array(
					'title'=>'基本信息',
					'list'=>array(
							array('name'=>'type','title'=>'商户类型','type'=>'radio','options'=>'merch_type','help'=>'商城店铺模式下，不存在营业时间，将失效！'),
							array('type'=>'string','must'=>true,'title'=>'商城名称','name'=>'merchname'),
							array('type'=>'image','title'=>'商城logo','name'=>'logo'),
							array('type'=>'text','title'=>'商城简介','name'=>'desc'),
							array('type'=>'text','title'=>'商户公告','name'=>'remark'),
							array('type'=>'string','title'=>'主营项目','name'=>'salecate'),
							array('name'=>'cateid','must'=>true,'title'=>'商户分类','type'=>'select','options'=>'cate','option_title'=>'catename'),
							array('type'=>'string','title'=>'店铺联系人','name'=>'realname'),
							array('type'=>'string','title'=>'店铺手机','name'=>'mobile'),
							array('type'=>'pcd','title'=>'店铺区域','name'=>'pcd'),
							array('type'=>'string','title'=>'店铺地址','name'=>'address'),
							array('type'=>'lat_lng','must'=>true,'title'=>'店铺坐标','name'=>'lat_lng'),
							array('name'=>'snsid','title'=>'选择小区','type'=>'choose','action'=>'jy_merch/get_sns/'),
							array('name'=>'offline','title'=>'休息?','type'=>'switch'),
							array('type'=>'time_hour','title'=>'营业时间','name'=>'onlinetime'),
							array('name'=>'is_moregoods','title'=>'堂食扫餐桌号支持追加商品?','type'=>'switch','show'=>array('type'=>1),'help'=>'开启后：堂食扫餐桌号支持追加商品，部分正餐店需要，后面可以追加菜品，食用后再消费付款！'),
							array('name'=>'is_wm','title'=>'外卖模式','type'=>'switch','help'=>'开启后：支持外卖模式！'),
							array('name'=>'is_cash','title'=>'收银台结账','type'=>'switch','show'=>array('type'=>1),'help'=>'开启后：只能收银台结账！'),
							array('name'=>'cashtype','title'=>'收银台类型','type'=>'radio','options'=>'cashtype','help'=>''),
							//array('name'=>'datamids','title'=>'选择操作员','type'=>'choose_many','action'=>'core/member.get_member/many','help'=>'只有查看商户数据的权限！'),	
							array('type'=>'image','title'=>'店招','name'=>'topimg'),
							array('name'=>'tel','title'=>'商户电话','type'=>'string'),
							array('type'=>'switch','title'=>'开启客服','name'=>'iskefu','help'=>'开启客服后，会进入客服界面，没开启，点击拨打客服电话！'),
							array('type'=>'switch','title'=>'支持分销','name'=>'iscommission','help'=>'支持分销后，别的商户，可以选择添加您的商品到自己的小店，客户购买后享受佣金（佣金比例跟《微客分销》参数保持一致）！'),
							array('type'=>'switch','title'=>'可被复制','name'=>'is_share','help'=>'开启可复制后,他人可以一键复制你的店铺商品,店铺LOGO,描述等！'),
							array('name'=>'codeimg','title'=>'营业执照/许可证','type'=>'images'),
							array('name'=>'content','title'=>'商户详情','type'=>'richtext'),
							
					)
				),
				array(
					'title'=>'快递/配送/自提设置',
						'list'=>array(
							array('name'=>'sendtype','title'=>'默认配送方式','type'=>'radio','options'=>'sendtypes','help'=>'<red>如果总平台指定了《配送方式》本设置无效！</red>'),
							array('type'=>'checkbox','title'=>'支持方式','name'=>'opensendtype','options'=>'sendtypes','help'=>'如果留空，默认跟随商城系统；如果快递配送，同城配送都支持，优先同城配送，超出范围使用快递配送；'),
							array('name'=>'mypeisong','title'=>'是否自己配送','type'=>'switch','help'=>'不开启，则由平台配送员统一配送！','show'=>array('type'=>1)),
							array('type'=>'switch','title'=>'需要制作？','name'=>'ismake','help'=>'开启后，商户有需要制作的过程，制作完成后，后台点发货，配送员才能接单！'),
							array('type'=>'switch','title'=>'自动接单？','name'=>'isjiedan','help'=>'开启后，商户无需点击接单，自动接单！(如果是商家线下收款模式，自动接单将失效，商家必须手动接单，才能确定订单的有效性！)'),
							array('name'=>'out_pay','title'=>'配送费','type'=>'string','help'=>'开启《自己配送》后才生效，否则是由系统配送员配送，费用也是由系统决定','show'=>array('type'=>1)),
							array('name'=>'out_price','title'=>'起送金额','type'=>'string','show'=>array('type'=>1)),
							array('name'=>'man_fee','title'=>'满额免配送费','type'=>'string','help'=>'开启《自己配送》后才生效，否则是由系统配送员配送，费用也是由系统决定','show'=>array('type'=>1)),
							array('name'=>'out_juli','title'=>'最大配送距离','type'=>'unitstring','unit'=>'KM','help'=>'留空则由平台统一','show'=>array('type'=>1)),
							array('name'=>'out_upfee','title'=>'打包费','type'=>'unitstring','unit'=>'元','help'=>'留空则为0！','show'=>array('type'=>1)),
						)
				),
				array(
					'title'=>'收款人信息/二维码',
					'list'=>array(
						array('name'=>'payopenid','title'=>'选择收款人','type'=>'choose_title','action'=>'core/member.get_member/'),
						array('type'=>'image','title'=>'群聊二维码','name'=>'qunewm'),
						array('type'=>'switch','title'=>'付款二维码？','name'=>'isxxpay','help'=>'开启后，自定义到付款二维码！'),
						array('type'=>'image','title'=>'微信支付二维码','name'=>'zhifuewm'),
						array('type'=>'unitstring','unit'=>'次','name'=>'xnipay','title'=>'用户每次支付虚拟币','help'=>'支付码牌支付'),
						array('name'=>'setting.ks_id','title'=>'快手号','type'=>'string'),
						array('name'=>'setting.bankcard','title'=>'收款银行账户','type'=>'string'),
						array('name'=>'setting.realname','title'=>'收款账户名称','type'=>'string'),
						array('name'=>'bankimg','title'=>'银行卡照片','type'=>'image'),
						array('name'=>'zhaoshangid','title'=>'招商代理绑定ID','type'=>'string'),
					)
				),
				array(
					'title'=>'店铺风格设置',
					'list'=>array(
						array('type'=>'tip','title'=>'【温馨提示】：默认是“基本设置”已经指定了店铺风格。本小店设置的风格优先生效！'),
						array('type'=>'radio_tpl','title'=>'我的小店显示风格','name'=>'myshop_tpl','options'=>'myshop_tpls'),
					)
				),
				array(
					'title'=>'奖励设置',
					'list'=>array(
						array('type'=>'unitstring','unit'=>'%','name'=>'sets.red_rate','title'=>'会员下单红包返现比例'),
						array('type'=>'unitstring','unit'=>'%','name'=>'setting.paifee','title'=>'商家让利%','show'=>array('jy_paimerch'=>1)),
						//array('type'=>'unitstring','unit'=>'%','name'=>'sets.ti_max','title'=>'每天可提现最大红包','help'=>'金额再1~最大的金额，随机获取红包到零钱，一天只能零钱一次'),
					)
			),
			)
	);
	if($this->setting['isone_wechat']){
		$htmls['edits'][]=array(
				'title'=>'独立微信支付',
				'list'=>array(
					array('type'=>'tip','title'=>'【<red>温馨提示</red>】：
					</br>1、一定要在微信支付商户后台配送好微信支付的回调域名，否则不能正常支付回调！
					<br>2、JSAPI支付授权目录：'.$account_tp.'，兼容插件支付授权目录：'.$account_apitp.'
					<br>3、扫码回调链接：'.$account_url.'
					<br>4、微信支付商户的密钥不对，也可能导致支付回调异常（支付成功后：可能订单状态还是未支付）。'
					),
					array('type'=>'switch','title'=>'开启独立微信支付？','name'=>'onewechat.isopen','help'=>'开启后，商户可以设置自己的微信公众号，微信支付商户等！'),	
					array('type'=>'radio','title'=>'公众号类型','name'=>'onewechat.type', 'options'=>'types','help'=>'请设置正确的公众号类型，以免出错！(非认证服务号，可以借用系统认证服务号权限，否则无法微信一键登录，获取粉丝信息等；如果是认证服务号，需移步《微信公众号平台》--》接口设置--》网页授权回调域名，设置好域名才能正常使用！)'),
					array('type'=>'string','title'=>'AppID','name'=>'onewechat.appid','help'=>'填写公众号开发者AppID。登陆微信公众平台——开发——基本配置——开发者ID'),
					array('type'=>'string','title'=>'AppSecre','name'=>'onewechat.appsecret','help'=>'填写公众号开发者AppSecret。登陆微信公众平台——开发——基本配置——开发者密钥'),
					array('type'=>'string','title'=>'原始ID','name'=>'onewechat.oldid','help'=>'填写公众号原始ID。登陆微信公众平台——设置——公众号设置——帐号详情——原始ID'),
					array('type'=>'string','title'=>'微信支付商户号','name'=>'onewechat.wechat_mchid'),
					array('type'=>'string','title'=>'商户支付密钥','name'=>'onewechat.wechat_miyue','help'=>'如果是服务商支付，此处填写服务商支付密钥'),
					array('type'=>'upfile','title'=>'CRET证书文件'.$cert_remark,'name'=>'cert_file','help'=>'下载证书 cert.zip 解压后，上传 apiclient-cert.pem 文件。'),
					array('type'=>'upfile','title'=>'KEY密钥文件'.$key_remark,'name'=>'key_file','help'=>'下载证书 cert.zip  解压后，上传 apiclient-key.pem 文件。'),	
					array('type'=>'tip','title'=>'公众号绑定方法（授权模式添加公众号请忽略此步骤）：根据提示填写上述参数之后，将以下三项参数填至微信公众平台——开发——基本配置——服务器配置，启用，提交即可。'),
					array('type'=>'tip','title'=>'<red>[token验证失败?]:如果是https的：微信目前HTTPS他是有安全门槛的，达不到ATS安全标准证书或SSL证书安装不规范，就算安装了HTTPS也是不会通过微信认证；如果是其他原因，可以百度搜索一下自行排查。</red>' ),
					array('type'=>'copy','title'=>'服务器地址','name'=>'url', 'help'=>'' ),
					array('type'=>'copy','title'=>'令牌（Token）','name'=>'onewechat.token','help'=>'' ),
					array('type'=>'copy','title'=>'消息加解密密钥(EncodingAESKey)','name'=>'onewechat.aeskey','help'=>''),
					array('type'=>'help','title'=>'小程序独立支付参数'),
					array('type'=>'string','title'=>'小程序appid','name'=>'onewechat.minappid','help'=>'填写微信小程序appid' ),
					array('type'=>'string','title'=>'小程序appsecret','name'=>'onewechat.minappsecret','help'=>'填写微信小程序 appsecret' ),
					array('type'=>'radio','title'=>'微信支付类型','name'=>'minsub_pay','options'=>'wechat_types','help'=>'<red>1、如果用同主体的微信支付：只需移步小程序官方后台--微信支付--关联商户号，添加管理微信支付商户，选择《普通商户支付》填写支付商户参数即可！2、如果是非同主体的特约子商户，就只能选择《服务商支付》</red>'),
					array('type'=>'string','name'=>'onewechat.minmchid','show'=>array('minsub_pay'=>0),'title'=>'微信支付商户号(mchid)','help'=>'微信支付商户号，从微信商户平台获取（开通微信支付的通知邮件中也有）'),
					array('type'=>'string','title'=>'微信服务商appid','name'=>'onewechat.minmch_appid','show'=>array('minsub_pay'=>1),'help'=>'服务商appid'),
					array('type'=>'string','title'=>'微信服务商商户号','name'=>'onewechat.minmchid','show'=>array('minsub_pay'=>1),'help'=>'主服务商mch_id'),
					array('type'=>'string','title'=>'微信子商户subappid','name'=>'onewechat.minsub_appid','options'=>'wechats','show'=>array('minsub_pay'=>1),'help'=>'[<red>温馨提示</red>]:这边必须选择子商户的sub_appid，子商户sub_appid配置流程：https://kf.qq.com/faq/190715yaYnYv1907153mmIbA.html'),
					array('type'=>'string','title'=>'微信子商户号','name'=>'onewechat.minsub_mch_id','show'=>array('minsub_pay'=>1),'help'=>'子商户sub_mch_id'),
					array('type'=>'string','name'=>'onewechat.minpaykey','title'=>'微信支付密钥','help'=>'设置微信支付密钥，需要和微信商户平台的api密钥保持一致'),
				)
		);
		$return['wechat_types']=array(
			'0'=>'普通商户支付',
			'1'=>'服务商支付',
		);
	}
	if($this->setting['isone_allinpay']){
		$allinpay_url=str_replace('http://','',$account_host).'addons/jy_allinpay/notify.php';
		$item['allinpay_pay_types']=$item['setting']['allinpay_pay_types'];
		$htmls['edits'][]=array(
				'title'=>'通联支付',
				'list'=>array(
					array('type'=>'tip','title'=>'通联支付-H5收银台：https://aipboss.allinpay.com/know/devhelp/main.php?pid=38
					</br>第一步，向业务人员申请商户号。
					</br>第二步，登录商服后台https://vsp.allinpay.com/login配置相关参数。
					</br>回调地址：'.$allinpay_url.'
					'),
					array('type'=>'radio','title'=>'优先方式','name'=>'setting.allinpay_showtype','options'=>'allinpay_showtype','help'=>'优先其他支付：其他支付方式没有的，才显示通联支付类型；优先通联支付：如果通联支付有的，就优先使用通联支付的支付类型！'),
					array('type'=>'string','title'=>'集团商户号','name'=>'setting.allinpay_orgid','help'=>'共享集团号参数时必填'),
					array('type'=>'string','title'=>'商户号','name'=>'setting.allinpay_cusid','help'=>'实际交易商户号;'),
					array('type'=>'string','title'=>'应用ID','name'=>'setting.allinpay_appid','help'=>'平台分配的APPID'),
					//array('type'=>'string','title'=>'应用密钥','name'=>'setting.allinpay_key','help'=>'平台分配的KEY'),
					array('type'=>'text','title'=>'RSA私钥(PKCS1格式，非JAVA适用)','name'=>'setting.allinpay_rsakey'),
					array('type'=>'text','title'=>'RSA通联公钥','name'=>'setting.allinpay_pubkey','help'=>'验签用通联公钥，不是商户公钥;'),
					array('type'=>'checkbox','title'=>'支付支持类型','name'=>'allinpay_pay_types','options'=>'allinpay_types','help'=>'务必前往通联支付：开通相应的支付'),
		));
	}
	if($this->setting['isone_credit']){
		$htmls['edits'][]=array(
				'title'=>'独立虚拟币支付',
				'list'=>array(
					array('type'=>'radio','title'=>'开启金币交易','name'=>'onecredit.credit3','options'=>'credit_status'),
					//array('type'=>'string','title'=>'金币重命名','name'=>'onecredit.credit3_title'),
					array('type'=>'string','title'=>'金币交易抵扣比例','name'=>'onecredit.credit3_rate','help'=>'默认1：1交易，填10表示：10：1交易（10个抵扣1元）'),
					array('type'=>'unitstring','unit'=>'%','title'=>'最大抵现比例','name'=>'onecredit.credit3_dirate','help'=>'默认100%抵扣，如果填写50，表示最大抵扣订单额度的50%'),
					array('type'=>'radio','title'=>'开启元宝交易','name'=>'onecredit.credit4','options'=>'credit_status'),
					//array('type'=>'string','title'=>'元宝重命名','name'=>'onecredit.credit4_title'),
					array('type'=>'string','title'=>'元宝交易抵扣比例','name'=>'onecredit.credit4_rate','help'=>'默认1：1交易，填10表示：10：1交易（10个抵扣1元）'),
					array('type'=>'unitstring','unit'=>'%','title'=>'最大抵现比例','name'=>'onecredit.credit4_dirate','help'=>'默认100%抵扣，如果填写50，表示最大抵扣订单额度的50%'),
					array('type'=>'radio','title'=>'开启备用金交易','name'=>'onecredit.credit5','options'=>'credit_status'),
					//array('type'=>'string','title'=>'备用金重命名','name'=>'onecredit.credit5_title'),
					array('type'=>'string','title'=>'备用金交易抵扣比例','name'=>'onecredit.credit5_rate','help'=>'默认1：1交易，填10表示：10：1交易（10个抵扣1元）'),
					array('type'=>'unitstring','unit'=>'%','title'=>'最大抵现比例','name'=>'onecredit.credit5_dirate','help'=>'默认100%抵扣，如果填写50，表示最大抵扣订单额度的50%'),
					array('type'=>'radio','title'=>'开启R币交易','name'=>'onecredit.credit6','options'=>'credit_status'),
					//array('type'=>'string','title'=>'R币重命名','name'=>'onecredit.credit6_title'),
					array('type'=>'string','title'=>'R币交易抵扣比例','name'=>'onecredit.credit6_rate','help'=>'默认1：1交易，填10表示：10：1交易（10个抵扣1元）'),
					array('type'=>'unitstring','unit'=>'%','title'=>'最大抵现比例','name'=>'onecredit.credit6_dirate','help'=>'默认100%抵扣，如果填写50，表示最大抵扣订单额度的50%'),
				)
		);
	}
	if($this->setting['isone_app']){
		$htmls['edits'][]=array(
				'title'=>'下载APP',
				'list'=>array(
					array('type'=>'switch','title'=>'支持下载APP？','name'=>'app.isopen'),	
					array('type'=>'copy','title'=>'APP下载地址','name'=>'appurl','help'=>''),
					array('type'=>'ewm','title'=>'APP下载二维码','name'=>'appurl','help'=>''),
					array('type'=>'copy','title'=>'APP安装包地址','name'=>'app.installbak','help'=>'由平台总部统一上传'),
				)
		);
	}
	if($this->plugin_exists('jy_paimerch')){
		$jy_paimerch=plugin('jy_paimerch')->plugin_setting('basic');
		$return['jy_paimerch']=$item['jy_paimerch']=$jy_paimerch['isopen'];
	}
	if($this->plugin_exists('jy_newpaimerch')){
		$jy_newpaimerch=plugin('jy_newpaimerch')->plugin_setting('basic');
		$return['jy_newpaimerch']=$item['jy_paimerch']=$jy_newpaimerch['isopen'];
	}
	if($_SESSION['os']=='windows'){
		$return['htmls']=$htmls;
	}
	$citypeisong=plugin('jy_weishop')->plugin_setting('citypeisong');
	$return['sendtypes']=array(
		'1'=>'同城配送',
		'2'=>'到店自取',
		'4'=>'快递配送',
	);
	$return['merch_type']=$this->merch_type;
	$return['cashtype']=$this->cashtype;
	$return['account']=$_SESSION['account'];
	$return['extradata']=array();
	$newmerch_type=$this->merch_types;
	$newmerch_type2[]='暂无类型';
	foreach($newmerch_type as $type=>$mv){
		$newmerch_type2[]=$mv;
		$newcates[$type]=pdo_getall('jy_merch_category',array('uniacid'=>$_SESSION['uniacid'],'type'=>$type),array('id','catename'));
		foreach($newcates[$type] as $k=>&$gv){
			if($item['cateid']==$gv['id']){
				$item['pcateindex']=$k;
			}
		}
	}
	$return['newmerch_type']=$newmerch_type2;
	$return['newcates']=$newcates;
	$return['cate']=pdo_getall('jy_merch_category',array('uniacid'=>$_SESSION['uniacid']),array('id','catename'));
	foreach($return['cate'] as $k=>&$gv){
		if($item['cateid']==$gv['id']){
			$item['pcateindex']=$k;
		}
	}
	$item['merch_type']=pdo_getcolumn('jy_merch_category',array('id'=>$item['cateid'],'uniacid'=>$_SESSION['uniacid']),'type');
	$item['merch_type']=intval($item['merch_type']);
	$return['post']=$return['item']=$item;
	$return['myshop_tpls']=array(
		array('id'=>1,'title'=>'默认风格','image'=>'../addons/jy_merch/resource/images/tpl00.png'),
		array('id'=>2,'title'=>'小店风格','image'=>'../addons/jy_merch/resource/images/tpl01.png'),
	);
	if($this->plugin_exists('jy_merchcmi')){
		$return['myshop_tpls'][]=array('id'=>3,'title'=>'吃米风格','image'=>'../addons/jy_merch/resource/images/tpl02.png');
	}
	if($_SESSION['os']=='mobile'){
		$return['htmls']=$this->template_url('manage/shop_index');
	}
	$return['province']=cfc('tools')->pcd();
	$return['allinpay_types']=array(
		'alipay_url'=>'支付宝支付',
		'wechat'=>'微信支付',
		'union_online'=>'银联H5支付',
	);
	$return['allinpay_showtype']=array(0=>'不使用通联支付',1=>'优先其他支付',2=>'优先通联支付',3=>'仅使用通联支付');
	$return['credit_status']=array(0=>'不启用',1=>'启用交易',2=>'只显示不能交易');
	$return['snslist']=pdo_getall('jy_merch_sns',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	if($postdata['myshop_tpl']==3 && !$this->plugin_exists('jy_merchcmi')){
		exi('您还未安装吃米风格，不能选择该风格！','error');
	}
	if($_SESSION['os']!='windows' &&  $_SESSION['container']!='wxapp' && $setting['is_smscode'] && !check_sms_code($postdata['smscode'])){
		exi('手机验证码错误！','error');
	}
	if(!$postdata['pcd']['city']){
		//exi('请选择商户城市','error');
	}
	if(!$postdata['merchname']){
		exi('商户名称必填','error');
	}
	$postdata['lat_lng']=$postdata['addressinfo']['lat_lng']?:$postdata['lat_lng'];
	if(!$postdata['lat_lng']){
		exi('请填写坐标！','error');
	}
	$postdata['address']=$postdata['addressinfo']['address']?:$postdata['address'];
	if(!$postdata['address']){
		exi('请填写详细地址！','error');
	}
	if($this->plugin_exists('jy_newpaimerch')){
		if($postdata['setting']['paifee'] && (intval($postdata['setting']['paifee'])<5 || intval($postdata['setting']['paifee'])>100)){
			exi('商家让利必须大于等于5，小于等于100！','error');
		}
		$postdata['setting']['paifeenew']=$postdata['setting']['paifee'];
	}
	
	$merchid=pdo_getcolumn('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid),'id');
	if($postdata){
		$postdata['onewechat']['cert_file']=$postdata['cert_file'];
		$postdata['onewechat']['key_file']=$postdata['key_file'];
		$postdata['onewechat']['minsub_pay']=$postdata['minsub_pay'];
		$postdata['setting']['bankimg']=$postdata['bankimg'];
		$postdata['setting']['allinpay_pay_types']=$postdata['allinpay_pay_types'];
		$data =array(
			'type'=>intval($postdata['type']),
			'merchname'=>trim($postdata['merchname']),
			'topimg'=>trim($postdata['topimg']),
			'salecate'=>trim($postdata['salecate']),
			'desc'=>$postdata['desc'],
			'remark'=>$postdata['remark'],
			'logo'=>$postdata['logo'],
			'realname'=>trim($postdata['realname']),
			'mobile'=>trim($postdata['mobile']),
			'offline'=>intval($postdata['offline']),
			'onlinetime'=>ijson_encode($postdata['onlinetime']),
			'address'=>trim($postdata['address']),
			'is_share'=>intval($postdata['is_share']),
			'iscommission'=>intval($postdata['iscommission']),
			'iskefu'=>intval($postdata['iskefu']),
			'myshop_tpl'=>intval($postdata['myshop_tpl']),
			'detail_tpl'=>intval($postdata['detail_tpl']),
			'cateid'=>intval($postdata['cateid']),
			'star'=>intval($postdata['star']),
			'sudu'=>intval($postdata['sudu']),
			'isrecommand'=>$postdata['isrecommand'],
			'tel'=>$postdata['tel'],
			'out_pay'=>$postdata['out_pay'],
			'out_price'=>$postdata['out_price'],
			'man_fee'=>$postdata['man_fee'],
			'salenum'=>$postdata['salenum'],
			'groupid'=>$postdata['groupid'],
			'payopenid'=>$postdata['payopenid'],
			'isbrand'=>$postdata['isbrand'],
			'content'=>trim($postdata['content']),
			'mypeisong'=>$postdata['mypeisong'],
			'ismake'=>intval($postdata['ismake']),
			'isjiedan'=>intval($postdata['isjiedan']),
			'codeimg'=>ijson_encode($postdata['codeimg']),
			'pcd'=>ijson_encode($postdata['pcd']),
			'out_juli'=>$postdata['out_juli'],
			'out_upfee'=>$postdata['out_upfee'],
			'diyformdata'=>ijson_encode($postdata['diyfields']),
			'sendtype'=>intval($postdata['sendtype']),
			'opensendtype'=>trim($postdata['opensendtype']),
			'sets'=>ijson_encode($postdata['sets']),
			'onewechat'=>ijson_encode($postdata['onewechat']),
			'onecredit'=>ijson_encode($postdata['onecredit']),
			'setting'=>ijson_encode($postdata['setting']),
			'is_moregoods'=>intval($postdata['is_moregoods']),
			'qunewm'=>trim($postdata['qunewm']),
			'zhifuewm'=>trim($postdata['zhifuewm']),
			'isxxpay'=>intval($postdata['isxxpay']),
			'recommend'=>trim($postdata['recommend']),
			'special'=>trim($postdata['special']),
			'peisongtime'=>intval($postdata['peisongtime']),
			'is_wm'=>intval($postdata['is_wm']),
			'is_cash'=>intval($postdata['is_cash']),
			'cashtype'=>intval($postdata['cashtype']),
			'cash_commison'=>intval($postdata['cash_commison']),
			'no_vipshow'=>intval($postdata['no_vipshow']),
			'no_daan'=>intval($postdata['no_daan']),
			'xnipay'=>trim($postdata['xnipay']),
			'snsid'=>intval($postdata['snsid']),
		);
		if($postdata['lat_lng']['lat'] && $postdata['lat_lng']['lng']){
			$data['lat_lng']=ijson_encode($postdata['lat_lng']);
		}
		$isadd=pdo_get('jy_merch_user',array('mobile'=>$data['mobile'],'uniacid'=>$_SESSION['uniacid']),array('id'));
		if($merchid){
			if($isadd['id']!=$merchid){
				//exi('该手机号已申请过！','error');
			}
			pdo_update('jy_merch_user',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid));
			if($data['dd_shop_id']){
				model('jy_weishop/order/dada_api')->upshop($data);
			}
		}else{
			if($isadd['id']){
				exi('该手机号已申请过！','error');
			}
			$data['uniacid']=$_SESSION['uniacid'];
			$data['mid']=$_SESSION['uid'];
			$data['applytime']=time();
			pdo_insert('jy_merch_user',$data);
		}
		//添加客服
		$install = check_account_permission('jy_kefu');
		if($install){
			$member=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('nickname','avatar','mobile','groupid'));
			$kefuinfo=array(
				'nickname'=>trim($member['nickname']),
				'number'=>$postdata['mobile']?trim($postdata['mobile']):trim($member['mobile']),
				'picurl'=>trim($member['avatar']),
				'plugin'=>trim($member['plugin']),
				'pid'=>intval($merchid),
				'mid'=>$_SESSION['uid'],
			);
			$kefuinfo['type']=0;
			$kefuinfo['name']='kefu'.$_SESSION['uid'];
			model('jy_kefu/kefu')->add($kefuinfo);
			$kefuinfo['type']=1;
			$kefuinfo['name']='kefu1_'.$_SESSION['uid'];
			model('jy_kefu/kefu')->add($kefuinfo);
			$kefuinfo['type']=2;
			$kefuinfo['name']='kefu2_'.$_SESSION['uid'];
			model('jy_kefu/kefu')->add($kefuinfo);
		}else{
			//exi('无法开启客服，联系管理员开启<全网客服>','error');
		}
	}
	exi('设置成功','','goback');
}
if($_RQ['op']=='diy'){
	exi('','','/manage.shopdiy/');
}
if($_RQ['op']=='openvoice'){
	$post=get_postdata();
	$isopenvoice=intval($_RQ['isopenvoice']);
	pdo_update('jy_merch_user',array('isopenvoice'=>$isopenvoice),array('uniacid'=>$_SESSION['uniacid'],'id'=>$merchid));
	exi('设置成功！');	
}